using HCore.IOC.Context.Event.Attr;
using HCore.Unity.Behaviour;
using HCore.Unity.Manager;
using JetBrains.Annotations;

namespace UI.UIGame.Loading
{
    [BindPrefab(prefabName: "Loading")]
    public class LoadingVisual : HCoreMonoBehaviour
    {
        private ComponentData mBackgroundComponentData;
        private ComponentData mSubTitleComponentData;
        private ComponentData mTitleComponentData;

        protected override void Awake()
        {
            base.Awake();
            mBackgroundComponentData = Get("Background");
            mTitleComponentData = Get("Process/Title");
            mSubTitleComponentData = Get("Process/SubTitle");
        }

        private void Start()
        {
            SetTitle("手动填写 - Process/Title");
            SetSubTitle("手动填写 - Process/SubTitle");
        }

        public void SetTitle(string title)
        {
            mTitleComponentData.SetText(title);
        }

        public void SetSubTitle(string title)
        {
            mSubTitleComponentData.SetText(title);
        }

        [UsedImplicitly]
        [EventListener]
        private void OnLoadingProcessEvent(LoadingProcessEvent loadingProcessEvent)
        {
            var title = loadingProcessEvent.Title;
            var subTitle = loadingProcessEvent.SubTitle;

            if (title != null) SetTitle(title);
            if (subTitle != null) SetSubTitle(subTitle);

            // TODO 这里暂时还没有实现进度条。先这样过渡一下，以后再实现
        }
    }
}